#pragma once
#include <iostream>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

#define Path "./fifo"
#define Mode 0666
class Fifo
{
public:
    Fifo(const std::string& path)
        :_path(path)
    {
        umask(0);
        int n = mkfifo(_path.c_str(),Mode);
        if(n == 0)
        {
            std::cout << "mkFifo success" << std::endl;
        }
        else
        {
            std::cout << "mkFifo fail"<< " "<< "errno:" << errno << "strerror:" << strerror(errno) << std::endl;
        }
    }

    ~Fifo()
    {
        int n = unlink(_path.c_str());
        if (n == 0)
        {
            std::cout << "rmFifo success" << std::endl;
        }
        else
        {
            std::cout << "rmFifo fail"<< " "<< "errno:" << errno << "strerror:" << strerror(errno) << std::endl;
        }
    }

private:
    std::string _path; // 文件路径+文件名
};